/*
 * @Author: guanyaoming guanyaoming@linklogis.com
 * @Date: 2022-10-25 11:05:05
 * @LastEditors: guanyaoming guanyaoming@linklogis.com
 * @LastEditTime: 2023-06-27 13:37:22
 * @FilePath: \icf-agw-front\src\router\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*
 * @Author: guanyaoming guanyaoming@linklogis.com
 * @Date: 2022-10-25 11:05:05
 * @LastEditors: guanyaoming guanyaoming@linklogis.com
 * @LastEditTime: 2023-06-07 16:15:11
 * @FilePath: \icf-agw-front\src\router\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Vue from "vue";
import VueRouter from "vue-router";
import store from "@/store/index";

Vue.use(VueRouter);

const routes = [
    {
        path: "/",
        name: "login",
        component: () =>
            import(/* webpackChunkName: "login" */ "@/views/login/login.vue"),
    },
    {
        path: "/login",
        redirect: "/",
    },
    // {
    //     path: "/layout",
    //     component: () =>
    //         import(
    //             /* webpackChunkName: "layout" */ "@/views/layout/layout.vue"
    //         ),
    //     children: [
    //         /** 首页 */
    //         {
    //             path: "/Home",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "home" */ "@/views/home/home.vue"
    //                 ),
    //             name: "首页",
    //             meta: {
    //                 isNeedCheckPermission: true,
    //             },
    //         },

    //         {
    //             path: "/LayoutHedaerList",
    //             component: () =>
    //                 import("@/views/layout/components/LayoutHedaerList.vue"),
    //         },
    //         {
    //             path: "/layouDetail",
    //             component: () =>
    //                 import("@/views/layout/components/detail/detail.vue"),
    //         },
    //         //ataProtection
    //         {
    //             path: "/dataProtection",
    //             component: () =>
    //                 import("@/views/layout/components/dataProtection.vue"),
    //         },
    //         /** 我的工作台 */
    //         {
    //             path: "/taskTodo",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "taskTodo" */ "@/views/workflow/taskTodo/taskTodo.vue"
    //                 ),
    //             name: "待办任务",
    //             meta: {
    //                 isNeedCheckPermission: true,
    //                 keepAlive: true,
    //             },
    //         },
    //         {
    //             path: "/taskTodo/taskTodoDetail",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "taskTodoDetail" */ "@/views/workflow/taskTodoDetail/taskTodoDetail.vue"
    //                 ),
    //             name: "任务详情",
    //             meta: {
    //                 isNeedCheckPermission: true,
    //             },
    //         },
    //         // 保理-省专
    //         {
    //             path: "/provinceOrderQuery",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "orderList" */ "@/views/factoringBusiness/provinceOrderQuery/provinceOrderQueryList/provinceOrderQueryList.vue"
    //                 ),
    //             name: "融资载体信息查询",
    //             meta: {
    //                 isNeedCheckPermission: true,
    //                 keepAlive: true,
    //             },
    //         },
    //         {
    //             path: "/provinceOrderQuery/provincialCollegeDetail",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "orderDetail" */ "@/views/factoringBusiness/provinceOrderQuery/provinceOrderQueryDetail/provinceOrderQueryDetail.vue"
    //                 ),
    //             name: "订单详情",
    //             meta: {
    //                 isNeedCheckPermission: true,
    //             },
    //         },
    //         {
    //             path: "/dataLedgerProvincial",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "dataProtection" */ "@/views/dataLedger/dataLedgerProvincial.vue"
    //                 ),
    //             name: "数据保台账-省专",
    //             meta: {
    //                 isNeedCheckPermission: true,
    //                 keepAlive: true,
    //             },
    //         },
    //         {
    //             path: "/accountQuery",
    //             component: () =>
    //                 import("@/views/customerResources/accountQuery.vue"),
    //             name: "账户信息查询",
    //             meta: {
    //                 isNeedCheckPermission: true,
    //                 keepAlive: true,
    //             },
    //         },
    //         //签发管理
    //         {
    //             path: "/issuanceManagement",
    //             component: () =>
    //                 import(
    //                     "@/views/digitaldebtVoucher/IssuanceMenu/issuanceManagement.vue"
    //                 ),
    //             name: "签发管理",
    //             meta: {
    //                 isNeedCheckPermission: true,
    //                 keepAlive: true,
    //             },
    //         },
    //         {
    //             path: "/issuanceManagement/Detail",
    //             component: () =>
    //                 import(
    //                     "@/views/digitaldebtVoucher/IssuanceMenu/IssuancemanagementDetails.vue"
    //                 ),
    //             name: "数据债券凭证详情",
    //             meta: {
    //                 isNeedCheckPermission: true,
    //             },
    //         },
    //         {
    //             path: "/duePayment",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "digitaldebtVoucher/dueRedemption" */ "@/views/digitaldebtVoucher/dueRedemption/index"
    //                 ),
    //             name: "兑付管理",
    //         },
    //         {
    //             path: "/duePayment/detail",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "digitaldebtVoucher/dueRedemption" */ "@/views/digitaldebtVoucher/dueRedemption/components/redemptionDetail"
    //                 ),
    //             name: "兑付详情",
    //         },
    //         //已签发付款承诺
    //         {
    //             path: "/issuedDocument",
    //             component: () =>
    //                 import(
    //                     "@/views/digitaldebtVoucher/IssuedVoucher/voucherManagement.vue"
    //                 ),
    //             name: "签发管理",
    //             meta: {
    //                 isNeedCheckPermission: true,
    //                 keepAlive: true,
    //             },
    //         },
    //         //付款承诺详情
    //         {
    //             path: "/issuedDocument/voucherDetails",
    //             component: () =>
    //                 import(
    //                     "@/views/digitaldebtVoucher/IssuedVoucher/voucherDetails.vue"
    //                 ),
    //             name: "付款承诺详情",
    //             meta: {
    //                 isNeedCheckPermission: true,
    //             },
    //         },
    //         {
    //             path: "/issuedDocument/voucherDetails/detailsDate",
    //             component: () =>
    //                 import(
    //                     "@/views/digitaldebtVoucher/IssuedVoucher/components/detailsDate.vue"
    //                 ),
    //             name: "付款承诺详情",
    //             meta: {
    //                 isNeedCheckPermission: true,
    //             },
    //         },
    //         {
    //             path: "/issuedDocument/voucherDetails/earlySettlement",
    //             component: () =>
    //                 import(
    //                     "@/views/digitaldebtVoucher/IssuedVoucher/components/earlySettlement.vue"
    //                 ),
    //             name: "提前结清",
    //             meta: {
    //                 isNeedCheckPermission: true,
    //             },
    //         },
    //         /** 系统管理 */
    //         {
    //             path: "/userManageProv",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "userManage" */ "@/views/systemManage/userManage/userManage.vue"
    //                 ),
    //             name: "用户管理",
    //             meta: {
    //                 isNeedCheckPermission: true,
    //                 keepAlive: true,
    //             },
    //         },
    //         // UI 规范模板
    //         {
    //             path: "/UIDemoHome",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "UIDemoHome" */ "@/views/UIDemo/UIDemoHome"
    //                 ),
    //             name: "首页规范",
    //         },
    //         {
    //             path: "/UIDemoPageDetail",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "UIDemoPageDetail" */ "@/views/UIDemo/UIDemoPageDetail"
    //                 ),
    //             name: "详情页规范(多栏目)",
    //         },
    //         {
    //             path: "/UIDemoWorkflowDetail",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "UIDemoWorkflowDetail" */ "@/views/UIDemo/UIDemoWorkflowDetail"
    //                 ),
    //             name: "工作流详情页规范",
    //         },
    //         {
    //             path: "/UIDemoWorkflowDetail2",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "UIDemoWorkflowDetail2" */ "@/views/UIDemo/UIDemoWorkflowDetail2"
    //                 ),
    //             name: "工作流详情页(含影像树)",
    //         },
    //         {
    //             path: "/UIDemoSubmitInfDetail",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "UIDemoSubmitInfDetail" */ "@/views/UIDemo/UIDemoSubmitInfDetail"
    //                 ),
    //             name: "信息提交详情页规范",
    //         },
    //         {
    //             path: "/UIDemoSubmitInfDetail2",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "UIDemoSubmitInfDetail2" */ "@/views/UIDemo/UIDemoSubmitInfDetail2"
    //                 ),
    //             name: "信息提交详情页规范2",
    //         },
    //         {
    //             path: "/UIDemoTableList",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "UIDemoTableList" */ "@/views/UIDemo/UIDemoTableList"
    //                 ),
    //             name: "列表页规范",
    //         },
    //         {
    //             path: "/UIDemoTableList2",
    //             component: () =>
    //                 import(
    //                     /* webpackChunkName: "UIDemoTableList2" */ "@/views/UIDemo/UIDemoTableList2"
    //                 ),
    //             name: "列表页规范2",
    //         },
    //     ],
    // },
    {
        path: "/404",
        component: () =>
            import(/* webpackChunkName: "404" */ "@/views/404/index"),
        name: "404页面",
    },
    {
        path: "*",
        redirect: "/404",
    },
];

const router = new VueRouter({
    routes,
});
router.beforeEach((to, from, next) => {
    /**
     * 1、路由权限功能，当前接口没有返回的路由，直接在地址栏输入会进入 404 页面
     * 2、对于有子路由的页面，比如 taskTodo/taskTodoDetail, 会跟从父路由的权限，即 taskTodo 如果返回，taskTodo/taskTodoDetail 也能访问
     * 3、因为当前存于 vuex 中，所以刷新 isNeedCheckPermission: true 页面的时候会到404页面
     *  - 当前解决方法是如果路由可访问数组为空（有两种情况：一个是 刷新的时候 vuex 为空，另一个是真的没有路由权限，后端返回为空）的时候，不进行判断。
     *
     */
    if (to.meta.isNeedCheckPermission) {
        let path = to.path.split("/");
        path.length = 2;
        path = path.join("/");
        let canVisitMenu = Object.keys(store.state.menuPermission);
        if (!canVisitMenu.includes(path) && canVisitMenu.length) {
            next({ path: "/404" });
            return;
        }
    }
    next();
});

export default router;
